package logic.avatar
{
	import common.avatar.AvatarSprite;
	import common.core.GSprite;
	import common.utils.Vector2D;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	 
	public class Corpse extends AvatarSprite
	{
		public static const STATU_IDEA : String = "idea";
		public static const STATU_WALK : String = "walk";
		public static const STATU_EAT : String = "eat";
		public static const STATU_DEAD : String = "dead";
		
		private var m_id : String;
		
		private var vxcount : int;
		private var vycount : int;
		
		private var v2:Vector2D;
		
		public function Corpse()
		{
			vxcount = 0;
			vycount = 0;
			
			v2 = new Vector2D;
			
			curStatu = "eat";
		}
		
		private function detory() : void
		{
			m_id = null;
			vxcount = 0;
			vycount = 0;
		}
		
		private function checkStatu():void
		{
			
		}
		
		public override function collision(object:GSprite):void
		{
			if(object is Pand)
			{
				curStatu = STATU_EAT;
				
				v2.x = 2;
				v2.y = 1;
			}
		}
		
		public override function unCollision(object:GSprite):void
		{
			if(object is Pand)
			{
				var pand : Pand = object as Pand;
				
				if(pand.curStatu == Pand.STATU_ATTACK)
				{
		
				}
			}
		}
		
		/**
		 * 时时更新 
		 */		
		public override function update():void
		{
//			wander();
			
			this.x += v2.x;
			this.y += v2.y;
			
			super.update();
		}
		
		/**
		 * 漫游 
		 */		
		public function wander() : void
		{
			getRandomX();
			getRandomY();
			
			this.x += v2.x;
			this.y += v2.y;
			
			if(this.x + v2.x < activeRange.left)
			{
				v2.x = -v2.x;
				scaleX = -1;
			}
			else if(x + v2.x > activeRange.right)
			{
				v2.x = - v2.x;
				scaleX = 1;
			}
			
			if(this.y + v2.y < activeRange.top)
			{
				v2.y = -v2.y;
			}
			else if(y + v2.y > activeRange.bottom)
			{
				v2.y = - v2.y;
			}
		}
		
		private function getRandomX() : void
		{
			if(vxcount == 0)
			{
				var rnd : Number = Math.random();
				
				if(rnd>0.7)
				{
					v2.x = -Math.random()*3;
					this.scaleX = 1;
				}
				else if(rnd>0.4)
				{
					v2.x = 0;
				}
				else
				{
					v2.x = Math.random()*3;
					this.scaleX = -1;
				}
			}
			else if(vxcount == 100)
			{
				vxcount = -1;
			}
			
			vxcount ++;
		}
		
		private function getRandomY() : void
		{
			if(vycount == 0)
			{
				var rnd : Number = Math.random();
				
				if(rnd>0.7)
				{
					v2.y = -Math.random()*3;
				}
				else if(rnd>0.4)
				{
					v2.y = 0;
				}
				else 
				{
					v2.y = Math.random()*3;
				}
			}
			else if(vycount == 200)
			{
				vycount = -1;
			}
			
			vycount ++;
		}
	}
}